<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('店铺小程序列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="case-form">
                <div class="select-list"></div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <!--<a class="btn btn-primary multiple" onclick="addToTemplate(-1,1)" shiro:hasPermission="back:wechatOpen:addToTemplate">-->
                <!--<i class="fa fa-upload"></i> 提交到标准模板库-->
            <!--</a>-->
            <!--<a class="btn btn-warning multiple" onclick="addToTemplate(-1,0)" shiro:hasPermission="back:wechatOpen:addToTemplate">-->
                <!--<i class="fa fa-upload"></i> 提交到普通模板库-->
            <!--</a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var submitFlag = [[${@permission.hasPermi('back:wechatOpen:addToTemplate')}]];
    var prefix = ctx + "back/wechatOpen";



    $(function () {
        var options = {
            url: prefix + "/searchTemplateDraftList",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            sortName: "createTime",
            sortOrder: "desc",
            modalName: "代码草稿列表",
            height: 600,
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'draftId',
                    title: '草稿ID'
                },
                {
                    field: 'sourceMiniProgram',
                    title: '开发小程序名称'
                },
                {
                    field: 'sourceMiniProgramAppid',
                    title: '开发小程序ID'
                },
                {
                    field: 'userVersion',
                    title: '版本号'
                },
                {
                    field: 'userDesc',
                    title: '版本描述'
                },
                {
                    field: 'createTime',
                    title: '提交时间',
                    formatter: function(value,row,index){
                        return new Date(value*1000).toLocaleDateString();
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-xs ' + submitFlag + '" href="#" onclick="addToTemplate(\'' + row.draftId + '\',1)"><i class="fa fa-upload">提交到标准模板库</i></a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + submitFlag + '" href="#" onclick="addToTemplate(\'' + row.draftId + '\',0)"><i class="fa fa-upload">提交到普通模板库</i></a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function addToTemplate(draftId,templateType){
        var data = {draftIds:draftId,templateType:templateType};
        var templateTypeDesc = parseInt(templateType) == 0?"普通库":"标准库";
        if(parseInt(draftId)<0){
            rows = $.table.selectColumns('draftId');
            data.draftIds = rows.join();
            var tips = "确认批量上传草稿（"+data.draftIds+"）到【"+templateTypeDesc+"】吗？";
        }else{
            var tips = "确认单选上传草稿（"+data.draftIds+"）到【"+templateTypeDesc+"】吗？";
        }
        var isSearch = false;
        $.modal.confirm(tips, function () {
            $.modal.loading("上传处理中，请稍后...");
            $.post(prefix + "/addToTemplate", data, function (result) {
                if (result.code == web_status.SUCCESS) {
                    $.modal.alertSuccess(result.msg);
                    $.table.refresh();
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg);
                } else {

                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        });
    }
</script>
</body>
</html>